package com.dianping.cat.consumer.matrix.model.transform;

import com.dianping.cat.consumer.matrix.model.IEntity;
import com.dianping.cat.consumer.matrix.model.IVisitor;
import com.dianping.cat.consumer.matrix.model.entity.Matrix;
import com.dianping.cat.consumer.matrix.model.entity.MatrixReport;
import com.dianping.cat.consumer.matrix.model.entity.Ratio;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  13 */   private Stack<Object> m_objs = new Stack();

  private MatrixReport m_matrixReport;


  public DefaultMerger() {}

  public DefaultMerger(MatrixReport matrixReport) {
/*  21 */     this.m_matrixReport = matrixReport;
/*  22 */     this.m_objs.push(matrixReport);
  }


/*  26 */   public MatrixReport getMatrixReport() { return this.m_matrixReport; }



/*  30 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  34 */     this.m_objs.push(to);
/*  35 */     from.accept(this);
    this.m_objs.pop();
  }


/*  40 */   protected void mergeMatrix(Matrix to, Matrix from) { to.mergeAttributes(from); }


  protected void mergeMatrixReport(MatrixReport to, MatrixReport from) {
/*  44 */     to.mergeAttributes(from);
/*  45 */     to.getDomainNames().addAll(from.getDomainNames());
  }


/*  49 */   protected void mergeRatio(Ratio to, Ratio from) { to.mergeAttributes(from); }



  public void visitMatrix(Matrix from) {
/*  54 */     Matrix to = (Matrix)this.m_objs.peek();

/*  56 */     mergeMatrix(to, from);
/*  57 */     visitMatrixChildren(to, from);
  }

  protected void visitMatrixChildren(Matrix to, Matrix from) {
/*  61 */     for (Ratio source : from.getRatios().values()) {
/*  62 */       Ratio target = to.findRatio(source.getType());

/*  64 */       if (target == null) {
/*  65 */         target = new Ratio(source.getType());
/*  66 */         to.addRatio(target);
      }

/*  69 */       this.m_objs.push(target);
/*  70 */       source.accept(this);
/*  71 */       this.m_objs.pop();
    }
  }


  public void visitMatrixReport(MatrixReport from) {
/*  77 */     MatrixReport to = (MatrixReport)this.m_objs.peek();

/*  79 */     mergeMatrixReport(to, from);
/*  80 */     visitMatrixReportChildren(to, from);
  }

  protected void visitMatrixReportChildren(MatrixReport to, MatrixReport from) {
/*  84 */     for (Matrix source : from.getMatrixs().values()) {
/*  85 */       Matrix target = to.findMatrix(source.getName());

/*  87 */       if (target == null) {
/*  88 */         target = new Matrix(source.getName());
/*  89 */         to.addMatrix(target);
      }

/*  92 */       this.m_objs.push(target);
/*  93 */       source.accept(this);
/*  94 */       this.m_objs.pop();
    }
  }


  public void visitRatio(Ratio from) {
/* 100 */     Ratio to = (Ratio)this.m_objs.peek();

/* 102 */     mergeRatio(to, from);
/* 103 */     visitRatioChildren(to, from);
  }

  protected void visitRatioChildren(Ratio to, Ratio from) {}
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/matrix/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */